@echo off
title Ruoyi-ai Application Start Script

set APP_NAME=ruoyi-admin
set JAR_NAME=ruoyi-admin.jar
set APP_HOME=%~dp0
set JAR_PATH=%APP_HOME%target\%JAR_NAME%

REM JVM 参数配置 (针对2GB内存环境优化)
set JAVA_OPTS=-Xms256m -Xmx1024m
set JAVA_OPTS=%JAVA_OPTS% -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true
set JAVA_OPTS=%JAVA_OPTS% -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseG1GC
set JAVA_OPTS=%JAVA_OPTS% -Xlog:gc*:file=%APP_HOME%logs\gc.log:time,tags:filecount=3,filesize=5M

REM 更新GC日志参数以兼容新版本Java (在Windows上使用不同的参数)
set JAVA_OPTS=%JAVA_OPTS% -Xlog:gc*:file=%APP_HOME%logs\gc.log:time,tags:filecount=5,filesize=10M

REM Redis配置
set JAVA_OPTS=%JAVA_OPTS% -Dspring.data.redis.port=6666

REM 创建日志目录
if not exist "%APP_HOME%logs" mkdir "%APP_HOME%logs"

REM 检查Java环境部分已被移除

REM 检查应用jar包是否存在
if not exist "%JAR_PATH%" (
    echo Application jar not found: %JAR_PATH%
    echo Please build the project first with 'mvn clean package'
    pause
    exit /b 1
)

REM 启动应用
echo Starting %APP_NAME%...
echo JVM Options: %JAVA_OPTS%
echo JAR Path: %JAR_PATH%

start "Ruoyi-ai Application" /D "%APP_HOME%" java %JAVA_OPTS% -jar "%JAR_PATH%"

echo %APP_NAME% is starting in a new window.
echo Check logs in %APP_HOME%logs\ for more details.
pause